;(function () {
  const elevator = document.querySelector('.xtx-elevator')
  const backTop = document.querySelector('#backTop')
  window.addEventListener('scroll', function () {
    let n = window.document.documentElement.scrollTop
    elevator.style.opacity = n >= 300 ? 1 : 0
  })
  backTop.addEventListener('click', function () {
    window.scrollTo(0, 0)
  })
})()
  ; (function () {
    const elevator = document.querySelector('.xtx-elevator')
    const GOODS = document.querySelector('.xtx_goods_new ')
    const popular = document.querySelector('.xtx_goods_popular')
    const brand = document.querySelector('.xtx_goods_brand')
    const topic = document.querySelector('.xtx_goods_topic')
    elevator.addEventListener('click', function (e) {
      if (e.target.tagName === 'A') {
        switch (e.target.dataset.name) {
          case 'GOODS':
            window.scrollTo(0, GOODS.offsetTop)
            break
          case 'popular':
            window.scrollTo(0, popular.offsetTop)
            break
          case 'brand':
            window.scrollTo(0, brand.offsetTop)
            break
          case 'topic':
            window.scrollTo(0, topic.offsetTop)
            break
        }
      }
    })
    window.addEventListener('scroll', function () {
      let n = document.documentElement.scrollTop
      elevator.querySelector('a.active') && elevator.querySelector('a.active').classList.remove('active')
      if ( n >=GOODS.offsetTop && n<popular.offsetTop ) {
        elevator.querySelector('a[ data-name="GOODS"]').classList.add('active')
      } else if (n >= popular.offsetTop && n < brand.offsetTop) {
        elevator.querySelector('a[ data-name="popular"]').classList.add('active')
      } else if (n >= brand.offsetTop && n < topic.offsetTop) {
        elevator.querySelector('a[ data-name="brand"]').classList.add('active')
      } else if (n >= topic.offsetTop ) {
        elevator.querySelector('a[ data-name="topic"]').classList.add('active')
      }
    })
  })
();
